"use strict";
/* Controllers */
app.controller("costQuotaListController", ['$scope', '$location', '$rootScope', '$routeParams', 'costQuotaListService', function ($scope, $location, $rootScope, $routeParams, costQuotaListService) {

    var vm = $scope.vm = {};
    vm.p = {};
    vm.result = {};

    var errorFn = function (result) {
        alert(result);
    };

    $scope.listCostQuota = function (t) {
        var vm = $scope.vm;
        $scope.listCostQuota();
    };

    $scope.listCostQuota = function () {
        var vm = $scope.vm;
        vm.result.ms = "...";
        var param = vm.p;
        var procFn = function (response) {
            vm.result.ms = response.ms;
            var data = response.data;
            if (data == null) {
                return;
            }
            //vm.result.data = data;
            $('#list_table2').bootstrapTable('load', data);
        };
        costQuotaListService.listCostQuota(param, procFn, errorFn);
    };

    $scope.initializeController = function () {
        $scope.vm.result.ms = '';

        var $resultTable2 = $('#list_table2');
        $resultTable2.bootstrapTable({
             pageList: [30, 50, 100, 300, 500, 1000], pageSize: 30
        });
//        $resultTable2.bootstrapTable('hideColumn', 'basicPaths');
//        $resultTable2.bootstrapTable('hideColumn', 'updateTime');

        $scope.listCostQuota();
    };

    $scope.initializeController();

}]);



/* Services */
app.service('costQuotaListService', ['ajaxService', function (ajaxService) {

    this.listCostQuota = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/cost_report/listCostQuota.do", successFunction, errorFunction);
    };

}]);


function costQuotaIdFmt(value, row, index) {
    return [
        '<a href="#/sre/cost/cost_quota_add/', value, '" target="_blank">', " <u>管理</u>", '</a>'
    ].join('');
}

function actionFmt(value, row, index) {
    if(value==null) {
        return '-';
    }
    if(value==0 || value==1)  {
        return '有效'
    }
    return ' <font color=red>无效</font>'
}


function notifyFmt(value, row, index) {
    if(value==null) {
        return '-'
    }
    if(value==1) {
        return '全员'
    }
    return '个人'
}
